export default {
  namespaced: true,

  state: {
    token: uni.getStorageSync('token') || '',
    userinfo: uni.getStorageSync('userinfo') || {},
    address: uni.getStorageSync('address') || {},
    // 重定向的信息对象，包含属性： { url, type }
    redirectInfo: null
  },

  getters: {
    // 收货详细地址的计算属性
    fullAddress(state) {
      const { provinceName, cityName, countyName, detailInfo } = state.address
      if (!provinceName) return ""
      // 拼接 省，市，区，详细地址 的字符串并返回给用户
      return provinceName + cityName + countyName + detailInfo
    },
  },

  mutations: {
    // 更新重定向的信息对象
    setRedirectInfo(state, info) {
      state.redirectInfo = info
    },
    setToken(state, token) {
      state.token = token
      uni.setStorageSync('token', token)
    },
    updateUserInfo(state, userinfo) {
      state.userinfo = userinfo
      uni.setStorageSync('userinfo', userinfo)
    },
    setAddress(state, res) {
      state.address = res
      uni.setStorageSync('address', res)
    }
  },

  actions: {},
}